import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: lenovo
 * Date: 2023 -04 -04
 * Time: 10:13
 */
public class Work {
    public static void func(int[] arr) {
      int slow=0;
        for (int fast = 0; fast < arr.length; fast++) {
            if(arr[fast]>arr[slow]){
                arr[++slow]=arr[fast];
            }
        }
        System.out.println(slow+1);
        System.out.println(Arrays.toString(arr));
    }
        public static void main (String[]args){
            int[] arr = new int[]{1, 2, 3, 3, 4, 5, 5, 5, 6};
            func(arr);
        }
}
